package com.ewuyong.concurrence.example.atomic;

import com.ewuyong.concurrence.annotations.ThreadSafe;
import lombok.Data;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicReference;

@Slf4j
@ThreadSafe
@Data
public class AtomicExample5 {

    private static AtomicIntegerFieldUpdater<AtomicExample5> updater =  AtomicIntegerFieldUpdater.
            newUpdater(AtomicExample5.class, "count");

    @Getter
    private  Integer count = 100;

    public static void main(String[] args) {
        AtomicExample5 atomicExample5 = new AtomicExample5();
        updater.compareAndSet(atomicExample5, 100, 120);
        log.info("update success 1 , {}", atomicExample5.getCount());
    }

}
